package api

import (
	"api-getaway/basic/global"
	"api-getaway/handler/request"
	__ "api-getaway/proto"
	"github.com/gin-gonic/gin"
	"net/http"
)

func SendSms(c *gin.Context) {
	var req request.SendSmsReq
	if err := c.ShouldBind(&req); err != nil {
		c.JSON(http.StatusOK, gin.H{
			"message": "验证失败",
			"code":    400,
			"data":    err.Error(),
		})
		return
	}

	global.UserClient.SendSms(c, &__.SendSmsReq{
		Phone:  req.Phone,
		Course: req.Course,
	})

	c.JSON(http.StatusOK, gin.H{
		"message": "短信发送成功",
		"code":    200,
		"data":    nil,
	})

}

func Login(c *gin.Context) {
	var req request.LoginReq
	if err := c.ShouldBind(&req); err != nil {
		c.JSON(http.StatusOK, gin.H{
			"message": "验证失败",
			"code":    400,
			"data":    err.Error(),
		})
		return
	}

	user, _ := global.UserClient.LoginUser(c, &__.LoginUserReq{
		Name:        req.Name,
		Phone:       req.Phone,
		Sendsmscode: int64(req.SendsmsCode),
	})

	c.JSON(http.StatusOK, gin.H{
		"message": "登录成功",
		"code":    200,
		"data":    user,
	})
}

func List(c *gin.Context) {
	list, _ := global.UserClient.SubList(c, &__.SubListReq{})

	c.JSON(http.StatusOK, gin.H{
		"message": "展示成功",
		"code":    200,
		"data":    list,
	})
}

func Recommend(c *gin.Context) {
	var req request.RecommendReq
	if err := c.ShouldBind(&req); err != nil {
		c.JSON(http.StatusOK, gin.H{
			"message": "验证失败",
			"code":    400,
			"data":    err.Error(),
		})
		return
	}
	list, _ := global.UserClient.RecommendList(c, &__.RecommendListReq{
		Recommend: int64(req.Recommend),
	})

	c.JSON(http.StatusOK, gin.H{
		"message": "推荐成功",
		"code":    200,
		"data":    list,
	})

}
